<?php 
/**
 * Created by PhpStorm.
 * User: XIAOXIN
 * Date: 2021/4/7
 * Time: 15:11
 */
include_once "./request.php";

$openId = "TueU2W";
$openKey = "37fKYeAWs7GKXQpQgQh3P95ILZd0UfWY";

$ios_productCode = "91131120158043450755743622283983";
$android_productCode = "14802148287394050134777847863884";

$products = getProducts($openId, $openKey, $ios_productCode);
$userRole = getUserRole($openId, $openKey, $ios_productCode, $_GET['uid'], $_GET['username']);
$res = array(
    "products" => $products,
    "userRole" => $userRole,
);
echo $res;

function getProducts($openId, $openKey, $productCode) {
    $url = "http://quicksdk.dodjoy.com/open/goodsList";
    $params = array(
        "openId" => $openId,
        "productCode" => $productCode
    );
    $sign = getMd5Sign($params, $openKey);
    $data = array(
        "openId" => $openId,
        "productCode" => $productCode,
        "sign" => $sign
    );
    $result = curl_post_request($url, $data);
    return $result;
}

function getUserRole($openId, $openKey, $productCode, $uid, $username) {
    if(empty($uid) || empty($username)) {
        return array();
    }
    $url = "http://45.43.59.250:10001/ygame/ygame_role_select.php";
    $params = array(
        "uid" => $uid,
        "username" => $username,
        "productCode" => $productCode
    );
    $sign = getMd5Sign($params, $openKey);
    $data = array(
        "uid" => $uid,
        "username" => $username,
        "productCode" => $productCode,
        "sign" => $sign
    );
    $result = curl_post_request($url, $data);
    return $result;
}
?>